package org.adorsys.aderp.jpa.xls;

import java.lang.reflect.Field;
import java.util.HashMap;

import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.ReflectionUtils.FieldCallback;

public class CollectingDateTimeFieldCallback implements FieldCallback {
	private final HashMap<String, String> collector;
	
	@Override
	public void doWith(Field field) throws IllegalArgumentException,
			IllegalAccessException {
		DateTimeFormat dateTimeFormat = field.getAnnotation(DateTimeFormat.class);
		if(dateTimeFormat==null) return;
		String pattern = dateTimeFormat.pattern();
		if(StringUtils.isNotBlank(pattern)){
			collector.put(field.getName(), pattern);
		}
		
	}

	public CollectingDateTimeFieldCallback(final HashMap<String, String> collector) {
		this.collector = collector;
	}

}
